package com.itheima.mystream;

import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/*
  //定义一个字符串数组，每一个字符串数据由姓名数据和年龄数据组合而成
        String[] strArray = {"林青霞,30", "张曼玉,35", "王祖贤,33", "柳岩,25"};
        把年龄大于25的保存
        把使用Stream流操作完毕的数据收集到Map集合中并遍历，字符串中的姓名作键，年龄作值
        //同类型不同数据用Strem.of

 */
public class Demo8 {
    public static void main(String[] args) {
        //定义数组
        //String[] strArray = {"林青霞,30", "张曼玉,35", "王祖贤,33", "柳岩,25"};
        //创建流对象判断
        //每个字符串进行分割,分割后的1索引值就是年龄
        //Stream<String> stringStream = Stream.of("林青霞,30", "张曼玉,35", "王祖贤,33", "柳岩,25").filter(s -> Integer.parseInt(s.split(",")[1]) > 25);
        //存入集合
        //删选大于25的
        Stream<String> stringStream = Stream.of("林青霞,30", "张曼玉,35", "王祖贤,33", "柳岩,25").filter(s -> Integer.parseInt(s.split(",")[1])>25);
        //遍历剩下的
        //stringStream.forEach(s -> System.out.println(s));
        //将剩下的元素存入集合中姓名为键,年龄为值,用流对象进行掉方法
        Map<String, Integer> collect = stringStream.collect(Collectors.toMap(s -> s.split(",")[0], s -> Integer.parseInt(s.split(",")[1])));
        Set<String> set = collect.keySet();
        for (String s : set) {
            Integer integer = collect.get(s);
            System.out.println(s+"..."+integer);
        }
    }

    }

